/*
 * Copyright (C) 2011 Olivier Pothin and contributors
 *
 * GNU General Public License v2.0
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

/** 
 * 
 * @author Olivier Pothin
 * @description Display a single word with chinese, french and pinyin equivalence
 *
 */
package opot.activities;

import java.util.ArrayList;
import java.util.List;

import opot.dto.Stat;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.LinearLayout;

import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphView.GraphViewData;

public class StatDisplayer extends Activity {

	List<GraphViewData> goodAnswerData;
	List<GraphViewData> badAnswerData;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);	
		setContentView(R.layout.statdisplayer);

		goodAnswerData = new ArrayList<GraphViewData>();
		badAnswerData= new ArrayList<GraphViewData>();

		Cursor c = getContentResolver().query(Stat.Stats.CONTENT_URI, null, null, null, "created asc");
		int i = 1;
		while (c.moveToNext()) {
			goodAnswerData.add(
					new GraphViewData(
							i,c.getInt(c.getColumnIndex(Stat.Stats.COLUMN_NAME_NB_GOOD_ANSWER))
					)
			);

			badAnswerData.add(
					new GraphViewData(
							i,c.getInt(c.getColumnIndex(Stat.Stats.COLUMN_NAME_NB_BAD_ANSWER))
					)
			);

			i++;

		}

		if (!goodAnswerData.isEmpty()) {
			GraphViewData[] d = goodAnswerData.toArray(new GraphViewData[i-1]);
			GraphView graphView = new GraphView(this,
					d,
					getString(R.string.progression_label),
					null,
					null);
			graphView.setStrokeColor(255, 81, 230, 195);
			graphView.setScrollable(true);

			LinearLayout layout = (LinearLayout) findViewById(R.id.graph);
			layout.addView(graphView);
		}

		if (!badAnswerData.isEmpty()) {

			GraphViewData[] bad_d = badAnswerData.toArray(new GraphViewData[i-1]);





			GraphView graphView_b = new GraphView(this,
					bad_d,
					getString(R.string.progression_label),
					null,
					null);

			graphView_b.setScrollable(true);


			LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
			layout.addView(graphView_b);
		}
	}

}
